<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<%
			response.addHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");
			response.setDateHeader("Expires", 0);
		%>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>月报填写</title>
		<link href="css/sys.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" type="text/css"
			href="jeasyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="jeasyui/themes/icon.css">
		<script src="js/jquery.js"></script>
		<script type="text/javascript" src="jeasyui/jquery.easyui.min.js"></script>
		<script type="text/javascript"
			src="jeasyui/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
		<style type="text/css">
			.showmonthlog{
				width: 100%;
				height: 150px;
			}
		</style>
		<script type="text/javascript">

 function monthsh(s) 
	{	//s=""2011-10-08;
		var d = new Date(Date.parse(s.replace(/-/g, "/")));
		var year = d.getFullYear();
		var month = d.getMonth() + 1;
		return year+"年"+month+"月";
	};
	$(function() {
		$("#seachstartmonth").attr("value", nowMonth());
		$("#seachendmonth").attr("value", nowMonth());
		WdatePicker({
			isShowWeek : true,
			dateFmt : 'yyyy-MM',
			eCont : "div1",
			onpicked : function(dp) {
				$("#showmymonthlog").empty();
				var url = "monthlog.do?method=getNowDateMonthLogList&nowmonth="
						+ dp.cal.getDateStr("yyyy-MM");
				showmonthlog(url);
			}
		});
	});
	function searchmonthlog() {
		if($("#seachstartmonth").val()==""){
			$.messager.alert("提示","开始月不能为空~~","info");
			return;
		}else if($("#seachendmonth").val()==""){
			$.messager.alert("提示","结束月不能为空~~","info");
			return;
		}else if($("#seachstartmonth").val()>$("#seachendmonth").val()){
			$.messager.alert("提示","开始月不能晚于结束月~~","info");
			return;
		}
		var url = "monthlog.do?method=searchMonthLogList&startmonth="
			+ $("#seachstartmonth").val()+"&endmonth="+$("#seachendmonth").val()+"&nowtime="+new Date();
		$("#showmymonthlog").empty();
		showmonthlog(url);
	}
	//添加模块
	function addmymonthlog() {
		$("#commitdate").attr("value", nowDate());
		$("#mymonthlog").show();
		$("#mymonthlog").dialog({
			title : "添加月报",
			modal : true,
			width : 780,
			height : 520,
			collapsible : true,
			minimizable : false,
			maximizable : false,
			buttons : [ {
				text : "提交",
				iconCls : "icon-ok",
				handler : function() {
					tijiao();
				}
			}, {
				text : "保存",
				iconCls : "icon-ok",
				handler : function() {
					baocun();
				}
			}, {
				text : "取消",
				iconCls : "icon-undo",
				handler : function() {
					quxiao();
				}
			} ]
		});
	}

	function baocun() {
		$("#iscommit").attr("value", 0);
		$("#mymonthform").form("submit", {
			url : "monthlog.do?method=addMonthLog",
			onSubmit : function() {
				var flag = true;
				if ($("#monthofyear").val() == "") {
					$.messager.alert("警告信息", "选择月份~~", "warning");
					flag = false;
				} else if ($("#monthcontent").val() == "") {
					$.messager.alert("警告信息", "输入月报内容~~", "warning");
					flag = false;
				}
				return flag;
			},
			success : function(data) {
				$("#mymonthlog").dialog("close");
				showmsg(data);
			}
		});
	}

	function tijiao() {
		$("#iscommit").attr("value", 1);
		$("#mymonthform").form("submit", {
			url : "monthlog.do?method=addMonthLog",
			onSubmit : function() {
				var flag = true;
				if ($("#monthofyear").val() == "") {
					$.messager.alert("警告信息", "选择月份~~", "warning");
					flag = false;
				} else if ($("#monthcontent").val() == "") {
					$.messager.alert("警告信息", "输入月报内容~~", "warning");
					flag = false;
				}
				return flag;
			},
			success : function(data) {
				$("#mymonthlog").dialog("close");
				showmsg(data);
			}
		});
	}
	function gengxin(){
		$("#mymonthform").form("submit", {
			url : "monthlog.do?method=updateMonthLog&nowtime="+new Date(),
			onSubmit : function() {
				var flag = true;
				if ($("#monthofyear").val() == "") {
					$.messager.alert("警告信息", "选择月~~", "warning");
					flag = false;
				} else if ($("#commitdate").val() == "") {
					$.messager.alert("警告信息", "选择填报日期~~", "warning");
					flag = false;
				} else if($("#monthcontent").val() == ""){
					$.messager.alert("警告信息", "输入工作月报内容~~", "warning");
					flag = false;
				} 
				return flag;
			},
			success : function(data) {
				$("#mymonthlog").dialog("close");
				showmsg(data);
			}
		});
		$("#showmymonthlog").empty();
		var url="monthlog.do?method=getNowDateMonthLogList&nowweek="
			+ $("#monthofyear").val()+"&nowtime="+new Date();
		showweeklog(url);
	}
	function updatemonthlog(monthlogid) {
		$.ajax({
			type : "POST",
			dataType : "json",
			url : "monthlog.do?method=getMonthLogByid&nowtime=" + new Date(),
			data : {
				"id" : monthlogid
			},
			success : function(data) {
				$("#id").attr("value", data.id);
				$("#iscommit").attr("value", data.iscommit);
				$("#userid").attr("value", data.userid);
				$("#monthofyear").attr("value", data.monthofyear);
				$("#completion").attr("value", data.completion);
				$("#commitdate").attr("value", data.commitdate);
				$("#monthcontent").attr("value", data.monthcontent);
				$("#questioncontent").attr("value", data.questioncontent);
				$("#nextmonthcontent").attr("value", data.nextmonthcontent);
			}
		});
		$("#mymonthlog").show();
		$("#mymonthlog").dialog({
			title : "更新月报",
			modal : true,
			width : 780,
			height : 520,
			collapsible : true,
			minimizable : false,
			maximizable : false,
			buttons : [{
				text : "更新",
				iconCls : "icon-ok",
				handler :function(){ gengxin();}
			},{
				text : "取消",
				iconCls : "icon-undo",
				handler : function(){quxiao();}
			}]
		});
	}
	function quxiao() {
		$("#mymonthlog").dialog("close");
	}

	function showmonthlog(url) {
		$
				.ajax({
					type : "get",
					dataType : "json",
					url : url,
					success : function(data) {
						$
								.each(
										data,
										function(index, monthlog) {
											var commitflag = "已经提交~~";
											if (monthlog.iscommit == 0) {
												commitflag = "<a href='javascript:void(0)' onclick=\"updatemonthlog('"+monthlog.id+"')\">修改</a>|<a href='javascript:void(0)' onclick=\"commitmonthlog('"+monthlog.id+"')\">提交</a>";
											}
											var monthshow = monthsh(monthlog.monthofyear);
											$("#showmymonthlog")
													.append(
															"<div id='"+monthlog.id+"' class='icon-worklog'>"
																	+ monthshow
																	+ "["
																	+ commitflag
																	+ "]</div><table width='100%' bgcolor='#F7FBFF'>"
																	+ "<tr><td align='right' width='18%'>提交时间：</td><td>"
																	+ monthlog.commitdate
																	+ "</td><td align='right' width='18%'>工作完成度：</td><td>"
																	+ monthlog.completion
																	+ "</td></tr>"
																	+ "<tr><td align='right' width='18%'>工作内容：</td><td colspan='5'><textarea class='showmonthlog' readonly='readonly'>"
																	+ monthlog.monthcontent
																	+ "</textarea></td></tr>"
																	+ "<tr><td align='right' width='18%'>工作内容：</td><td colspan='5'><textarea class='showmonthlog' readonly='readonly'>"
																	+ monthlog.questioncontent
																	+ "</textarea></td></tr>"
																	+ "<tr><td align='right' width='18%'>工作内容：</td><td colspan='5'><textarea class='showmonthlog' readonly='readonly'>"
																	+ monthlog.nextmonthcontent
																	+ "</textarea></td></tr></table>");
										});
					}
				});
	}
</script>
	</head>
	<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
		<div region="west" style="width: 200px; overflow: hidden" id="west">
			<div
				style="background-color: #E0EC00; margin-top: 1px; text-align: center;">
				<a href="javascript:void(0)" onclick="addmymonthlog()">添加月报</a>
			</div>
			<div id="div1" align="center"></div>
			<div
				style="background-color: #E0EC00; margin-top: 20px; text-align: center;">
				月报查询
			</div>
			<form action="">
				<div>
					<label>
						开始月:
					</label>
					<input type="text"" name="seachstartmonth" id="seachstartmonth" readonly="readonly"
					onfocus="WdatePicker({dateFmt:'yyyy-MM'})" class="Wdate"/>
				</div>
				<div>
					<label>
						结束月:
					</label>
					<input type="text" name="seachendmonth" id="seachendmonth" readonly="readonly" 
					onfocus="WdatePicker({dateFmt:'yyyy-MM'})" class="Wdate"/>
				</div>
				<div align="center">
					<a href="javascript:void(0)" class="easyui-linkbutton" plain="true"
						icon="icon-search" onclick="searchmonthlog()">查询</a>
				</div>
			</form>
		</div>
		<div id="mainPanle" region="center" >
			<div id="showmymonthlog">
				欢迎填写月报！
			</div>
		</div>
		<div id="mymonthlog" style="display: none; text-align: center;">
			<form action="" id="mymonthform" name="mymonthform" method="post">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="userid" id="userid">
				<input type="hidden" name="iscommit" id="iscommit">
				<table align="center" width="100%" >
					<tr>
						<td>
							月报月份：
						</td>
						<td>
							<input type="text" " name="monthofyear" id="monthofyear"
								onfocus="WdatePicker({dateFmt:'yyyy-MM'})" class="Wdate" readonly="readonly"/>
						</td>
						<td>
							工作完成度：
						</td>
						<td>
						<select name="completion" id="completion">
						<option value="100%">100%</option>
						<option value="90%">90%</option>
						<option value="80%">80%</option>
						<option value="70%">70%</option>
						<option value="60%">60%</option>
						<option value="50%">50%</option>
						<option value="40%">40%</option>
						<option value="30%">30%</option>
						<option value="20%">20%</option>
						<option value="10%">10%</option>
						</select>
						</td>
						<td>
							月报填报日期：
						</td>
						<td>
							<input type="text" " name="commitdate" id="commitdate" readonly="readonly"
								onfocus="WdatePicker({dateFmt:'yyyy-MM'})" class="Wdate" />
						</td>
					</tr>
					<tr>
						<td>
							月度总结：
						</td>
						<td colspan="5">
							<textarea name="monthcontent" id="monthcontent"
								style="width: 100%; height: 150px;"></textarea>
						</td>
					</tr>
					<tr>
						<td>
							问题记录：
						</td>
						<td colspan="5">
							<textarea name="questioncontent" id="questioncontent"
								style="width: 100%; height: 150px;"></textarea>
						</td>
					</tr>
					<tr>
						<td>
							下月工作计划：
						</td>
						<td colspan="5">
						<textarea name="nextmonthcontent" id="nextmonthcontent"
								style="width: 100%; height: 150px;"></textarea>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</body>
</html>
